#!/bin/bash -i
# Resolve all frontend dependencies that the application requires to develop.

# Stop on errors
set -e

cd "$(dirname "$0")/.."

# Install/upgrade node when inside devcontainer
if [[ -n "$DEVCONTAINER" ]]; then
    nodeCurrent=$(nvm version default || :)
    nodeLatest=$(nvm version-remote "$(cat .nvmrc)")
    if [[ -z "$nodeCurrent" || "$nodeCurrent" == "N/A" ]]; then
        nvm install
    elif [[ "$nodeCurrent" != "$nodeLatest" ]]; then
        nvm install --reinstall-packages-from="$nodeCurrent" --default
        nvm uninstall "$nodeCurrent"
    fi
fi

# Install node modules
    yarn install
